package cn.bigfire.wzdj.pojo.vo;

import cn.hutool.core.convert.Convert;
import cn.bigfire.wzdj.util.Consts;
import lombok.Data;

import java.util.List;

@Data
public class GoodsVO {

    Integer shopId;
    Integer goodsId;

//    Integer goods;
//    String name;
//    Integer pos;
//    Integer buyCond;
//    String buyCondTarget;
//    Integer sellRule;
//    Integer limitBuyType;
//    Integer limitBuyNum;
//    Integer rare;
    Integer free;
//    Integer productId;
//    Integer advertId;
//    Integer multiple;
//    String bgRes;
//    Integer templateId;
//    Integer costType;
//    Integer isShowLimit;

    String costId;
    String costName;
    String costNum;

    String rewardId;
    String rewardName;
    String rewardNum;

    public static GoodsVO of(int shopId,int goodsId,Goods goods) {
        GoodsVO goodsVO = Convert.convert(GoodsVO.class, goods);
//        GoodsVO goodsVO = new GoodsVO();
        goodsVO.setShopId(shopId);
        goodsVO.setGoodsId(goodsId);
        List<IdNum> costList = goods.getCost();
        StringBuilder costId = new StringBuilder();
        StringBuilder costName = new StringBuilder();
        StringBuilder costNum = new StringBuilder();
        for (IdNum idNum : costList) {
            costId.append("|").append(idNum.getId());
            costName.append("|").append(Consts.Item.nameById(idNum.getId()));
            costNum.append("|").append(idNum.getNum());
        }
        goodsVO.setCostId(costId.toString().replaceFirst("\\|", ""));
        goodsVO.setCostName(costName.toString().replaceFirst("\\|", ""));
        goodsVO.setCostNum(costNum.toString().replaceFirst("\\|", ""));

        List<IdNum> rewardList = goods.getReward();
        StringBuilder rewardId = new StringBuilder();
        StringBuilder rewardName = new StringBuilder();
        StringBuilder rewardNum = new StringBuilder();
        for (IdNum idNum : rewardList) {
            rewardId.append("|").append(idNum.getId());
            rewardName.append("|").append(Consts.Item.nameById(idNum.getId()));
            rewardNum.append("|").append(idNum.getNum());
        }
        goodsVO.setRewardId(rewardId.toString().replaceFirst("\\|", ""));
        goodsVO.setRewardName(rewardName.toString().replaceFirst("\\|", ""));
        goodsVO.setRewardNum(rewardNum.toString().replaceFirst("\\|", ""));
        return goodsVO;
    }


}
